package com.example.parkingsharing.ui.components.user

import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavController
import com.example.parkingsharing.data.ParkingSharingStrings


@Composable
fun AvatarButton(
    modifier: Modifier = Modifier,
    userAvatarId: Int = 0,
    isLogin: Boolean,
    navHostController: NavController,
) {
    // 显示用户头像
    Surface(
        modifier = modifier.size(60.dp),
        shape = CircleShape,
        color = MaterialTheme.colors.onSecondary.copy(alpha = 1f),
        contentColor = MaterialTheme.colors.primary,
    ) {
        if (isLogin) {
            // TODO("更新用户头像图片")
            // TODO("用户头像的获取来源：后端或本地缓存")
            Image(
                painter = painterResource(id = userAvatarId),
                contentDescription = ParkingSharingStrings.ContentDescription.ZH.userAvatar,
                alignment = Alignment.Center,
                modifier = Modifier.clickable(
                    enabled = true,
                    onClick = {
                        navHostController.navigate("LOGIN_SCREEN/{key1}/{key2}")
                    }
                )
            )
        } else {
            // 未登录则显示为登录
//            SelectionContainer() { // 设置文本可选择
            Row(verticalAlignment = Alignment.CenterVertically){
                Text(
                    text = ParkingSharingStrings.ContentDescription.ZH.login,
                    color = MaterialTheme.colors.onSurface,
                    fontSize = 20.sp,
                    textAlign = TextAlign.Center,
                    modifier = Modifier
                        .clickable {
                            // TODO("跳转到登录页面")
                            navHostController.navigate("LOGIN_SCREEN/{key1}/{key2}")
                        }
                        .fillMaxWidth()
                )
//            }
            }
        }
    }
}